#include "Pipeline.h"
#include <stack>
#include "SPVector4.h"
#include "SPVector3.h"
#include "SPColor.h"
#include "SPVertex.h"

namespace SP
{
	Pipeline::Pipeline(void)
	{
	}

	Pipeline::~Pipeline(void)
	{
	}

	void Pipeline::setInputVertex(const void* inputVertices, uint32 verticesCount)
	{
		mVertexData = inputVertices;
		mVertexCount = verticesCount;
	}

	void Pipeline::setTransformMatrix(const SPMatrix& matrix)
	{
		mTransformMatrix = matrix;
	}

	void Pipeline::setOutputBuffer(uint8* output)
	{
		mOutputBuffer = output;
	}

	void Pipeline::draw(uint32 primitiveType)
	{
		using std::stack;
		stack<SPVertex*> vsOutputBuffer;

		char* data = (char*)mVertexData;

		for (uint32 i = 0; i < mVertexCount; ++i)
		{
			SPVector4 position(*((SPVector3*)data));
			data += sizeof(SPVector3);
			SPColor* color = (SPColor*)data;
			data += sizeof(SPColor);

			position = position * mTransformMatrix;
			vsOutputBuffer.push(new SPVertex(position, *color));
		}
	}
}
